package homework.day03;

import java.io.FileInputStream;
import java.io.File;
import java.io.ObjectInputStream;
import java.io.IOException;
public class Test2 {
    public static void main(String[] args) {
        File file = new File(".");
        File[] subs = file.listFiles(f -> f.getName().contains("obj"));
        for (File sub : subs) {
            System.out.println(sub.getName());
            try (FileInputStream fis = new FileInputStream(sub);
                 ObjectInputStream ois = new ObjectInputStream(fis);
            ) {
                if (ois.readObject() instanceof String) {
                    String obj = (String) ois.readObject();
                    System.out.println(obj);
                    ois.close();
                }
            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
}

